<?
include('adodb/adodb-exceptions.inc.php'); 
require ("comun/ini.php");
if(isset($_POST['JsonEnv'])){
	$JsonRec = new Services_JSON();
	$JsonEnv = new Services_JSON();
	$JsonRec=$JsonRec->decode(str_replace("\\","",$_POST['JsonEnv']));

	try {
		$q = "SELECT COUNT(*) AS total, 
				(SELECT COALESCE(SUM(cantidad),-1) 
				 FROM limites_peritos 
				 WHERE id_tipo=$JsonRec->Tipo AND id_perito=$JsonRec->Perito ) AS limite 
			FROM experticias AS A 
				INNER JOIN tipos_experticia AS B ON A.id_tipo = B.id
			WHERE A.id_perito = $JsonRec->Perito
				AND A.id_tipo = $JsonRec->Tipo
				AND to_char(A.fecha,'mm')::integer = to_char('$JsonRec->Fecha'::date,'mm'::text)::integer 
				AND to_char(A.fecha,'yyyy')::integer = to_char('$JsonRec->Fecha'::date,'yyyy'::text)::integer
				AND A.id <> $JsonRec->Exp";
//		var_dump($q);
		$r = $conn->Execute($q);
		$i=0;
		while(!$r->EOF){
			$Limite[$i]['T'] = $r->fields['total'];
			$Limite[$i]['L'] = $r->fields['limite'];
			$i++;
			$r->movenext();
		}
		if(is_array($Limite)){
			echo $JsonEnv->encode($Limite);
		}else{
			echo false;
		}
	}catch( ADODB_Exception $e ){
		//	echo ERROR_CATCH_GENERICO;
		echo false;
	}
} 
?>